<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">

  <xsl:template match="*|/">
    <xsl:apply-templates/>
  </xsl:template>

  <xsl:template match="text()|@*">
    <xsl:value-of select="."/>
  </xsl:template>

  <xsl:template match='nbsp' name='nbsp'>
    <xsl:text disable-output-escaping='yes'>&amp;nbsp;</xsl:text>
  </xsl:template>

  <xsl:template name="rangeRecursive">
    <xsl:param name="index" select="1"/>
    <xsl:param name="selected" select="1"/>
    <xsl:param name="limit" select="31"/>
    <xsl:choose>
      <xsl:when test='$index = $selected'>
        <option value="{$index}" selected="true">
          <xsl:value-of select="$index"/>
        </option>
      </xsl:when>
      <xsl:otherwise>
        <option value="{$index}">
          <xsl:value-of select="$index"/>
        </option>
      </xsl:otherwise>
    </xsl:choose>
    <xsl:if test="$index &lt; $limit">
      <xsl:call-template name="rangeRecursive">
        <xsl:with-param name="index" select="$index + 1"/>
        <xsl:with-param name="selected" select="$selected"/>
        <xsl:with-param name="limit" select="$limit"/>
      </xsl:call-template>
    </xsl:if>
  </xsl:template>

  <xsl:template match="Registration/Step3">

    <script type="text/javascript">

      YAHOO.formRegistration.init = function () {
      function onPushButtonsMarkupReady() {
//      var oSubmitButton1 = new YAHOO.widget.Button("signup_submit", { id:"submitbutton1" });
      //      if( $('country').value != "none" )
      //      $('country').selectedIndex=0;

      function onRegistrationSubmit(e) {

      var ret = validateForm();
      if( ret != false ) {
      return;
      }

      YAHOO.util.Event.preventDefault(e);

      }

      YAHOO.util.Event.on("formRegistration", "submit", onRegistrationSubmit);

      }

      YAHOO.util.Event.onContentReady("formRegistration", onPushButtonsMarkupReady);

      } ();

      initLoadingContainer();

    </script>

    <script>
      function validateForm() {

      document.returnValue = false;

      var statura = document.getElementById("D302").value;
      if (!isPositiveInteger(statura )){
      alert("Inserisci una statura valida, dai!");
      return false;
      }else{
      document.returnValue = true;
      }

      document.returnValue = false;
      var peso = document.getElementById("D303").value;

      if (!isPositiveInteger(peso )){
      alert("Inserisci un peso valido, dai!");
      return false;
      }else{
      document.returnValue = true;
      }
      }


    </script>


    <form name="formRegistration" id="formRegistration" method="post" action="userProfileChange.aspx?step=4" onSubmit="validateForm();return document.returnValue">
      <div class="round_me" style="background:#FEEECC; padding:20px; margin:10px;">
        <table class="body" border="0">
          <tr>
            <td class='title' colspan='2'>
              <xsl:value-of select="@title"/>
              <br/>
              <br/>
            </td>
          </tr>
          <xsl:for-each select='Question'>
            <xsl:choose>

              <xsl:when test='@id="301"'>
                <tr>
                  <td>
                    <xsl:value-of select="@description"/>
                  </td>
                  <td>
                    <select size="1" name="D{@id}">
                      <xsl:for-each select="Answer">
                        <xsl:choose>
                          <xsl:when test='@id=../@answid'>
                            <option value="{@id}" selected="true">
                              <xsl:value-of select="."/>
                            </option>
                          </xsl:when>
                          <xsl:otherwise>
                            <option value="{@id}">
                              <xsl:value-of select="."/>

                            </option>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:for-each>
                    </select>
                  </td>
                </tr>
              </xsl:when>
              <xsl:when test='@id="302"'>
                <tr>
                  <td>
                    <xsl:value-of select="@description"/>
                  </td>
                  <td>
                    <select name="D{@id}" id="D{@id}">
                      <option value="none" selected="true" disabled="true">
                        altezza
                      </option>
                      <option value="" disabled="true">
                        ----
                      </option>
                      <xsl:call-template name="rangeRecursive">
                        <xsl:with-param name="index" select="140"/>
                        <xsl:with-param name="selected" select="@answid"/>
                        <xsl:with-param name="limit" select="210"/>
                      </xsl:call-template>
                    </select>
                  </td>
                </tr>
              </xsl:when>
              <xsl:when test='@id="303"'>
                <tr>
                  <td>
                    <xsl:value-of select="@description"/>
                  </td>
                  <td>
                    <select name="D{@id}" id="D{@id}">
                      <option value="none" selected="true" disabled="true">
                        peso
                      </option>
                      <option value="" disabled="true">
                        ----
                      </option>
                      <xsl:call-template name="rangeRecursive">
                        <xsl:with-param name="index" select="40"/>
                        <xsl:with-param name="selected" select="@answid"/>
                        <xsl:with-param name="limit" select="160"/>
                      </xsl:call-template>
                    </select>
                  </td>
                </tr>
              </xsl:when>
              <xsl:when test='@id="304"'>
                <tr>
                  <td>
                    <xsl:value-of select="@description"/>
                  </td>
                  <td>
                    <select size="1" name="D{@id}">
                      <xsl:for-each select="Answer">
                        <xsl:choose>
                          <xsl:when test='@id=../@answid'>
                            <option value="{@id}" selected="true">
                              <xsl:value-of select="."/>
                            </option>
                          </xsl:when>
                          <xsl:otherwise>
                            <option value="{@id}">
                              <xsl:value-of select="."/>

                            </option>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:for-each>
                    </select>
                  </td>
                </tr>
              </xsl:when>
              <xsl:when test='@id="305"'>
                <tr>
                  <td>
                    <xsl:value-of select="@description"/>
                  </td>
                  <td>
                    <select size="1" name="D{@id}">
                      <xsl:for-each select="Answer">
                        <xsl:choose>
                          <xsl:when test='@id=../@answid'>
                            <option value="{@id}" selected="true">
                              <xsl:value-of select="."/>
                            </option>
                          </xsl:when>
                          <xsl:otherwise>
                            <option value="{@id}">
                              <xsl:value-of select="."/>

                            </option>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:for-each>
                    </select>
                  </td>
                </tr>
              </xsl:when>
              <xsl:when test='@id="306"'>
                <tr>
                  <td>
                    <xsl:value-of select="@description"/>
                  </td>
                  <td>
                    <select size="1" name="D{@id}">
                      <xsl:for-each select="Answer">
                        <xsl:choose>
                          <xsl:when test='@id=../@answid'>
                            <option value="{@id}" selected="true">
                              <xsl:value-of select="."/>
                            </option>
                          </xsl:when>
                          <xsl:otherwise>
                            <option value="{@id}">
                              <xsl:value-of select="."/>
                            </option>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:for-each>
                    </select>
                  </td>
                </tr>
              </xsl:when>
              <xsl:when test='@id="307"'>
                <tr>
                  <td>
                    <xsl:value-of select="@description"/>
                  </td>
                  <td>
                    <select size="1" name="D{@id}">
                      <xsl:for-each select="Answer">
                        <xsl:choose>
                          <xsl:when test='@id=../@answid'>
                            <option value="{@id}" selected="true">
                              <xsl:value-of select="."/>
                            </option>
                          </xsl:when>
                          <xsl:otherwise>
                            <option value="{@id}">
                              <xsl:value-of select="."/>
                            </option>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:for-each>
                    </select>
                  </td>
                </tr>
              </xsl:when>
              <xsl:when test='@id="308"'>
                <tr>
                  <td>
                    <xsl:value-of select="@description"/>
                  </td>
                  <td>
                    <select size="1" name="D{@id}">
                      <xsl:for-each select="Answer">
                        <xsl:choose>
                          <xsl:when test='@id=../@answid'>
                            <option value="{@id}" selected="true">
                              <xsl:value-of select="."/>
                            </option>
                          </xsl:when>
                          <xsl:otherwise>
                            <option value="{@id}">
                              <xsl:value-of select="."/>
                            </option>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:for-each>
                    </select>
                  </td>
                </tr>
              </xsl:when>
              <xsl:when test='@id="309"'>
                <tr>
                  <td>
                    <xsl:value-of select="@description"/>
                  </td>
                  <td>
                    <select size="1" name="D{@id}">
                      <xsl:for-each select="Answer">
                        <xsl:choose>
                          <xsl:when test='@id=../@answid'>
                            <option value="{@id}" selected="true">
                              <xsl:value-of select="."/>
                            </option>
                          </xsl:when>
                          <xsl:otherwise>
                            <option value="{@id}">
                              <xsl:value-of select="."/>
                            </option>
                          </xsl:otherwise>
                        </xsl:choose>
                      </xsl:for-each>
                    </select>
                  </td>
                </tr>
              </xsl:when>


            </xsl:choose>
          </xsl:for-each>

          <tr>
            <td colspan='2' align='right' style='padding-top:20px;padding-bottom:10px;'>
              <p class="submit">
                <input type="submit" id="signup_submit" name="submit" value="Salva e prosegui con Interessi"></input>
              </p>
            </td>

          </tr>

        </table>
        <input type="hidden" name="email" id="email" value="{/Registration/user/@email}" />
      </div>
    </form>


  </xsl:template>

</xsl:stylesheet>